package com.springcloudserver.feignfallback;

import com.springcloudserver.common.AjaxResult;
import com.springcloudserver.service.UserInfoService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: chenzuolin
 * @time: 2021/3/27 14:40
 */
@Component
public class FeignServiceException implements FallbackFactory<UserInfoService> {

    Logger logger = LoggerFactory.getLogger(FeignServiceException.class);

    @Override
    public UserInfoService create(Throwable throwable) {
        return new UserInfoService() {

            @Override
            public AjaxResult findById(String id) {
                logger.error("UserInfoService.UserInfoService:{}",throwable.getMessage());
                return AjaxResult.error(throwable.getMessage());
            }

            @Override
            public AjaxResult findAll() {
                logger.error("UserInfoService.findAll:{}",throwable.getMessage());
                return AjaxResult.error(throwable.getMessage());
            }
        };
    }
}
